package com.baiwang.web;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class WebserviceClient {

    public static void main(String[] args) throws IOException {
        String url = "http://10.27.132.43/cwbase/service/SHFWJK/XSFPKPHX.asmx";
        String jsonInput = "{\"gsdm\":\"10011\",\"sjlx\":\"2\",\"czlx\":\"1\",\"djbh\":\"BSF100112404080003\",\"fpdm\":\"041002300111\",\"fphm\":\"31330299\",\"fplxdm\":\"026\",\"je\":500.0,\"se\":57.52,\"yxfpje\":500.0,\"yxfpse\":57.52,\"yxfphm\":\"31330299\",\"zsfs\":\"0\",\"zzjgdm\":\"814f887e24944295a03df07c05272bc2\"}";

        HttpURLConnection connection = null;
        try {
            // Create connection
            URL urlObj = new URL(url);
            connection = (HttpURLConnection) urlObj.openConnection();
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "application/json");
            connection.setDoOutput(true);

            // Send request
            DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
            wr.writeBytes(jsonInput);
            wr.flush();
            wr.close();

            // Get Response
            int responseCode = connection.getResponseCode();
            System.out.println("Response Code : " + responseCode);

            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String inputLine;
            StringBuilder response = new StringBuilder();

            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();

            // Print result
            System.out.println(response.toString());
        } finally {
            if (connection != null) {
                connection.disconnect();
            }
        }
    }
}
